package com.gombe.credit.app.ui.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.gombe.credit.app.GombeCreditApp
import com.gombe.credit.app.R
import com.gombe.credit.lib.adapter.GombeCreditRecyclerViewAdapter
import com.gombe.credit.lib.adapter.GombeCreditViewHolderHelper
import com.gombe.credit.lib.shapeview.layout.GombeCreditLinearLayout
import org.json.JSONObject

/**
 * GombeCredit
 * @Author wwdeng
 * @CreateTime: 2025/3/10 20:14
 * @Annotation：进件信息 - 选择Popupwindow item
 */
class AdapterGombeCreditStepSelectPopu(recyclerView: RecyclerView?) : GombeCreditRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.popupwindow_gombe_credit_step_general_select_item) {
    override fun setItemChildListener(helper: GombeCreditViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout) //点击Item
    }
    override fun fillData(helper: GombeCreditViewHolderHelper, position: Int, model: JSONObject) {
        val textTitle = helper.getTextView(R.id.textTitle)
        textTitle.text = model.optString("title")

        val itemLayout = helper.getView<GombeCreditLinearLayout>(R.id.itemLayout)
        val imgStatus = helper.getImageView(R.id.imgStatus)
        if (model.optBoolean("isSelect",false)) {
            imgStatus.setImageResource(R.mipmap.gombe_credit_circle_check_selected_icon)
            if (position == itemCount - 1){
                itemLayout.shapeDrawableBuilder
                    .setSolidColor(getColor(R.color.gombe_credit_fffff5b5))
                    .setBottomLeftRadius(GombeCreditApp.app.resources.getDimension(com.gombe.credit.lib.R.dimen.dp_12))
                    .setBottomRightRadius(GombeCreditApp.app.resources.getDimension(com.gombe.credit.lib.R.dimen.dp_12))
                    .intoBackground()
            } else {
                itemLayout.shapeDrawableBuilder
                    .setSolidColor(getColor(R.color.gombe_credit_fffff5b5))
                    .setBottomLeftRadius(GombeCreditApp.app.resources.getDimension(com.gombe.credit.lib.R.dimen.dp_0))
                    .setBottomRightRadius(GombeCreditApp.app.resources.getDimension(com.gombe.credit.lib.R.dimen.dp_0))
                    .intoBackground()
            }
        } else {
            imgStatus.setImageResource(R.mipmap.gombe_credit_circle_check_normal_icon)
            itemLayout.shapeDrawableBuilder.setSolidColor(getColor(R.color.transparent)).intoBackground()
        }
        if (position == itemCount - 1){
            helper.setVisibility(R.id.viewLine, View.INVISIBLE)
        } else {
            helper.setVisibility(R.id.viewLine, View.VISIBLE)
        }
    }
}